package com.quyunshuo.module.home.provider

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.quyunshuo.androidbaseframemvvm.base.utils.SpUtils
import com.quyunshuo.androidbaseframemvvm.common.constant.USER_INFO_DATA
import com.quyunshuo.androidbaseframemvvm.network.bean.UserInfo

//用户管理类
object UserManager {
    private val userLiveData = MutableLiveData<UserInfo>()

    /**
     * 保存用户信息
     * @param user
     */
    fun saveUserInfo(user: UserInfo) {
        SpUtils.putParcelable(USER_INFO_DATA, user)
        if (userLiveData.hasObservers()) {
            userLiveData.postValue(user)
        }
    }

    /**
     * 获取用户LiveData
     * @return LiveData<User>
     */
    fun getUserLiveData(): LiveData<UserInfo> {
        return userLiveData
    }
}